<?php

namespace Ionafan2\GetonlyimgBundle\Controller;

use Ionafan2\GetonlyimgBundle\Exception\Exception;
use Ionafan2\GetonlyimgBundle\Form\Type\UrlType;
use Ionafan2\GetonlyimgBundle\Services\Parser;
use phpDocumentor\Plugin\Core\Parser\DocBlock\Tag\Definition\Doctrine;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
    Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class IndexController extends Controller
{

    /**
     *
     * @Template()
     */
    public function indexAction(Request $request)
    {
        $form = $this->createForm(new UrlType());

        $links = array();

        if ($request->getMethod() == 'POST') {

            /** @var  $parser Parser */
            $parser = $this->get('parser');

            $form->submit($request);

            try {
                $links = $parser->parse($form->get('url')->getData());
            } catch (Exception $e) {

            }
        }

        return array('form' => $form->createView(), 'links' => $links);
    }

    /**
     *
     * @Template()
     */
    public function aboutAction()
    {
       return array();
    }

    /**
     *
     * @Template()
     */
    public function contactAction()
    {
       return array();
    }

}
